import request from '@/utils/request'
import { HTTP_METHOD } from '@/utils/http'

const BASE_URL = '/admin_message'

/**
 * @export 获取消息列表
 * @param {*} per_page
 * @param {*} page
 * @param {*} data
 * @return {*}
 */
export function getMessages (per_page, page, data) {
  return request({
    url: `${BASE_URL}/message_template_list`,
    method: HTTP_METHOD.GET,
    params: {
      per_page,
      page,
      ...data,
    },
  })
}

/**
 * @export 改变模板触发方式
 * @param {*} tid
 * @return {*}
 */
export function changeTemplateStatus (tid) {
  return request({
    url: `${BASE_URL}/on_off/${tid}`,
    method: HTTP_METHOD.PUT,
  })
}

/**
 * @export 修改消息模板
 * @param {*} tid
 * @return {*}
 */
 export function modifyTemplate (data) {
  return request({
    url: `${BASE_URL}/message_template_list`,
    method: HTTP_METHOD.PUT,
    data,
  })
}

/**
 * @export 获取模板
 * @param {*} tid 模板id
 * @return {*}
 */
export function getTemplate (tid, mode) {
  return request({
    url: `${BASE_URL}/template_detail/${tid}/${mode}`,
    method: HTTP_METHOD.GET
  })
}

/**
 * @export 获取消息发送记录
 * @param {*} per_page
 * @param {*} page
 * @param {*} data
 * @return {*} 
 */
export function getMessageRecords(per_page, page, data) {
  return request({
    url: `${BASE_URL}/message_record_list`,
    method: HTTP_METHOD.GET,
    params: {
      per_page, page,
      ...data
    }
  })
}

/**
 * @export 获取消息相亲
 * @param {*} id
 * @return {*} 
 */
export function getMessageRecord(id) {
  return request({
    url: `${BASE_URL}/message_record_detail/${id}`,
    method: HTTP_METHOD.GET,
  })
}